package com.ewanghuiju.app.presenter.shopmail;

import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.shopmail.TodayVogueContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.MailShopResponBean;
import com.ewanghuiju.app.model.http.exception.ApiException;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import java.util.List;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class 今日爆款
 * @time 2020/2/16
 */
public class TodayVoguePresenter extends RxPresenter<TodayVogueContract.View> implements TodayVogueContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public TodayVoguePresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }


    @Override
    public void getdata(int type,int page) {
        if (type == Constants.MAIL_TYPE_TODAY_HOT) {
        }
        addSubscribe(mDataManager.tbGoodsgao(page)
                        .compose(RxUtil.rxSchedulerHelper())
                        .compose(RxUtil.handleMyResultCannull())
                        .subscribeWith(new CommonSubscriber<Optional<List<MailShopResponBean>>>(mView) {
                            @Override
                            public void onNext(Optional<List<MailShopResponBean>> optional) {
                                if(mView!=null)
                                mView.showContent(optional.getIncludeNull());
                            }

                            @Override
                            public void onError(Throwable e) {
                                super.onError(e);
                                if(mView!=null)
                                mView.showContentError();
//                        if (e instanceof ApiException) {
//                        mView.showLoginResponseMsg(((ApiException) e).getCode(), e.getMessage());
//                        } else {
//                        }
                            }
                        })
        );

    }

    @Override
    public void getMoreData(int type,int page) {
        addSubscribe(mDataManager.tbGoodsgao(page)
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<List<MailShopResponBean>>>(mView) {
                    @Override
                    public void onNext(Optional<List<MailShopResponBean>> optional) {
                        if(mView!=null)
                        mView.showMoreContent(optional.getIncludeNull());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        if(mView!=null)
                        mView.showMoreContentError();
                        if (e instanceof ApiException) {
                        } else {
                        }
                    }
                })
        );
    }

}
